package com.miyake.dsp.common;

public class UnitConverter {
	public static double todB(double v) {
		if (v < 1e-12) {
			v = 1e-12;
		}
		return 10*Math.log10(v);
	}
	public static double todBm(double w) {
		if (w < 1e-12) {
			w = 1e-12;
		}
		return 10 * Math.log10(w * 1000.0); //dBm=10log10 (mW) 
	}
	public static double[] todBm(double[] w) {
		double ret[] = new double[w.length];
		for (int i = 0; i < ret.length; i++) {
			ret[i] = todBm(w[i]);
		}
		return ret;
	}
	public static double toW(double v) {
		return Math.pow(10.0, v/10.0) / 1000.0;
	}
	public static double[] toW(double[] v) {
		double ret[] = new double[v.length];
		for (int i = 0; i < ret.length; i++) {
			ret[i] = toW(v[i]);
		}
		return ret;
	}
	public static double toLinear(double bpfLevel) {
		return Math.pow(10.0, bpfLevel / 10.0);
	}
	public static double[] todB(double[] v) {
		double[] ret = new double[v.length];
		for (int i = 0; i < ret.length; i++) {
			ret[i]  = todB(v[i]);
		}
		return ret;
	}
}
